package com.simplesoftwares.client.library.appstructure;

import com.google.code.p.gwtchismes.client.GWTCAlert;
import com.google.code.p.gwtchismes.client.GWTCGlassPanel;
import com.simplesoftwares.client.library.appskeleton.AppMemory;
import com.simplesoftwares.client.library.appskeleton.ProcessLevelBar;
import com.simplesoftwares.client.library.appskeleton.ScreeenState;

/**
 * Ui Screen is top most class of any kind of screen.Abstracts logic common to all screens.
 * Conceptually this class is very important from flow point of view , may be it shows some properties 
 * of Master design pattern
 * @author Kamala
 *
 * @param <T>
 */
public abstract class UiScreen<T> extends ViewContainer {
	
	/**
	 * ProcessLevelBar objects.
	 */
	protected ProcessLevelBar processLevelBar;
	/**
	 * An object of SearchPopUpScreen if it is set to null,It means the class does not wants a search popup.
	 */
	protected SearchPopUpScreen<T>searchpopupscreen;
	
	protected String[] processlevelBarNames;
	
	/**
	 * Glass Panel covers the whole screen and doesn't allow user to do interaction on screen.
	 */
	protected GWTCGlassPanel glassPanel;
	
	/**
	 *Presenter refrence 
	 */
	protected EntityPresenter presenter;
	
	/**
	 * Creates a new Ui Screen.
	 */
	public UiScreen() {
		super();
		createScreen();
		toggleAppHeaderBarMenu();
		
		
	}

//////////////////////////////////////////////ABSTRACT METHODS/////////////////////////////////////////
	/**
	 * clears the screen
	 * @author Kamala
	 */
	public abstract void clear();
	/**
	 * validates the ui screen
	 * @return true if validation sucessfull .False if not
	 */
	
	public abstract boolean validate();
	/**
	 * Sets screen in enabled or disabled mode.
	 * @param state if true makes the screen enable
	 */
	
	public abstract void setEnable(boolean state);
	/**
	 * toogles the App header bar menu.
	 * To Do : Togelling logic depends upon screen,but some togelling also depends upon the screen state whoose logic we
	 * can write here and can make this method concrete.
	 */
	
	public abstract void toggleAppHeaderBarMenu();
	/**
	 * creates the screen. All concrete class will give its implementation.
	 * To Do: Introduce generators.
	 * @author Kamala
	 */
	
	public abstract void createScreen();
	/**
	 *  updates the model from view.
	 *  @param model the model object which needs to be updated from view.
	 */
	
	public abstract void updateModel(T model);
	/**
	 * updates the view from model.
	 * @param model
	 */
	
	public abstract void updateView(T model);

/////////////////////////////////////SETTING SCREEN STATES//////////////////////////////////////////////
	
	/**
	 * Sets the current state in new mode.Also hides the process level bar if it exists. 
	 */
	public void setToNewState() 
	{
		clear();
		AppMemory.getAppMemory().currentState=ScreeenState.NEW;
		toggleAppHeaderBarMenu();
		if(processLevelBar!=null)
		    processLevelBar.setVisibleFalse(false);
		setEnable(true);	
	}
	
	/**
	 * Sets the current state in view mode.Also shows the process level bar if it exists.
	 */
	
	public void setToViewState() 
	{
		AppMemory.getAppMemory().currentState=ScreeenState.VIEW;
		toggleAppHeaderBarMenu();
		if(processLevelBar!=null)
		    processLevelBar.setVisibleFalse(true);
		setEnable(false);
		
	}
	/**
	 * Sets the app in edit state.Also makes process level bar visible if exists.
	 */
	
	public void setToEditState() 
	{
		AppMemory.getAppMemory().currentState=ScreeenState.EDIT;
		toggleAppHeaderBarMenu();
		if(processLevelBar!=null)
		    processLevelBar.setVisibleFalse(true);
		setEnable(true);
	}

/////////////////////////////////INTERVAL METHODS/////////////////////////////////////////////
	
	
	public void showWaitSymbol() {
		glassPanel = new GWTCGlassPanel();
		glassPanel.show();
		
		
	}
	public void hideWaitSymbol() {
	   glassPanel.hide();
		
	}
	
//////////////////////////////////GETTER SETTERS///////////////////////////////////////////////
	
	public ProcessLevelBar getProcessLevelBar() {
		return processLevelBar;
	}
	public void setProcessLevelBar(ProcessLevelBar processLevelBar) {
		this.processLevelBar = processLevelBar;
	}
	public SearchPopUpScreen<T> getSearchpopupscreen() {
		return searchpopupscreen;
	}
	public void setSearchpopupscreen(SearchPopUpScreen<T> searchpopupscreen) {
		this.searchpopupscreen = searchpopupscreen;
	}
	
	

	/**
	 * Sets the counts whic returns from server on view.The method is a stub as many screens may not need this.
	 * 
	 * @param count count which returns from server
	 */
	public void setCount(int count) {
		
			
	}
	
	/**
	 * Method shows a pop up with a message
	 * @param Message
	 */
	public void showDialogMessage(String Message)
	{
		final GWTCAlert alert = new GWTCAlert(); 
	     alert.alert(Message);
	}
	
	public void showDialogMessage(String Message,int roundedBlue,int animation)
	{
		final GWTCAlert alert = new GWTCAlert(roundedBlue|animation); 
	     alert.alert(Message);
	}

	public String[] getProcesslevelBarNames() {
		return processlevelBarNames;
	}

	public void setProcesslevelBarNames(String[] processlevelBarNames) {
		this.processlevelBarNames = processlevelBarNames;
	}

	public GWTCGlassPanel getGlassPanel() {
		return glassPanel;
	}

	public void setGlassPanel(GWTCGlassPanel glassPanel) {
		this.glassPanel = glassPanel;
	}

	public EntityPresenter getPresenter() {
		return presenter;
	}

	public void setPresenter(EntityPresenter presenter) {
		this.presenter = presenter;
	}

	
	
	
}
